{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "60f6c266-7fab-43b9-978c-930e24e8ded7",
   "metadata": {},
   "source": [
    "## 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "35270e90-0928-4e09-8568-7d9fbf9d816f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import json\n",
    "import re\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "944e62f9-026f-43e2-a8e2-c104d59fcc7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "train = json.load(open('dataset/train.json'))\n",
    "test = json.load(open('dataset/test.json'))\n",
    "job_list = json.load(open('dataset/job_list.json'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2cd9a703-00bd-4c6a-accf-2cb9ace8a543",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(51, 20000, 6500)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(job_list), len(train), len(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "087ac07f-8edf-4725-aa37-a0b3153e96ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'positionName': '77 102 113 102 14859143 14846102 14856354 14725004 14860175',\n",
       " 'positionDescription': '54 14976902 14846085 14925705 15710888 14924977 15640254 14720169 15706553 15706534 15252363 14788542 14781097 15710888 14924977 14720387 15637383 14792325 14854539 14782359 14784945 14784899 14849419 14847384 15697082 15706553 15706534 15252380 53 14976902 14783927 14844318 15704195 15698820 14924964 14722950 15252363 14859953 14854539 14782359 14720191 14859667 14720387 14781831 14785448 14782848 14788260 15252380 52 14976902 15709080 15709092 15640254 14720169 14720387 15638449 14789042 14780320 14791308 15706258 14849419 14858370 15704454 14720387 14781831 14785448 14783400 14781318 14976901',\n",
       " 'positionRequirements': '54 14976902 15630474 14714302 15638181 14788518 14785451 14721174 14846093 14924962 14925709 14854817 14846337 15252363 15706534 14723472 14785469 14976902 15632285 14923942 14976902 14923942 14780072 14856354 14725004 14723726 14720191 14844596 14925716 14925725 15252363 14782353 14854334 15706534 14723472 14785469 14785422 14791316 14846365 14844595 15708580 14846093 14716606 15635128 14720387 14844593 14924945 14925716 14925725 15252380 53 14976902 14713240 14728324 77 102 113 102 15706282 15708039 15252363 14713240 14779790 77 53 66 66 14728340 14784899 15252363 14713240 14779790 84 115 117 114 115 116 14976902 84 119 117 110 105 96 14976902 79 110 101 98 117 105 102 115 98 14788225 14784945 15252380 52 14976902 14925185 15704228 72 117 102 100 107 98 14976902 67 69 53 14976902 84 86 75 84 98 117 113 98 117 14976902 74 126 84 86 75 14723726 14783159 14781097 14859668 14925738 14720387 14925703 14721162 15252380 51 14976902 14780314 15708328 14794626 14786231 15252363 14780314 14728371 14783112 14781104 15252363 14781602 14785422 14858412 15632280 14720387 14854817 14925479 15697082 14847388 15252363 14848387 14925193 14925705 14924945 14925245 14792088 15632285 14846600 14924443 15252363 14785422 14859197 14713999 14720387 14925709 15710364 14858372 14849419 14792325 14719138 14789557 14976901 14789283 14857616 14924426 14925757 14721174 14853024 15706536 15639705 15637633 14851237 14728344 14925703 14781596 15697567 14857616 14924426 15252363 14925245 14849695 15632285 15710336 14723463 14846337 14723740 15632270 14976902 14723987 15706258 14976902 14847898 15706258 14976902 14853002 15706258 14976902 14728335 14854566 14723726 14715304 15699333 14849929 14858898 14717871 14976901',\n",
       " 'positionID': '016'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_list[15]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "87b29659-ee2e-4a1c-8a43-e32e60479fde",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'positionName': '77 102 113 102 14859143 14846102 14856354 14725004 14860175',\n",
       " 'resumeData': {'profileEduExps': [{'schoolLevel': ['62 63 50', '53 54 54'],\n",
       "    'schoolOriginal': '14925738 14857910 14853024 14854817',\n",
       "    'courses': '',\n",
       "    'education': '14722706 14853292',\n",
       "    'majorOriginal': '14717874 14854807 14925705 15632285 14923942 14856354 14725004',\n",
       "    'endTimeOriginal': '53 55 53 53 14859955 55 49 14785423',\n",
       "    'duration': '53 54',\n",
       "    'educationOriginal': '14722706 14853292',\n",
       "    'major': '14717874 14854807 14925705 15632285 14923942 14856354 14725004',\n",
       "    'school': '14925738 14857910 14853024 14854817',\n",
       "    'startTimeOriginal': '53 55 53 55 14859955 55 62 14785423',\n",
       "    'GPA': '',\n",
       "    'ranking': '',\n",
       "    'startTime': '53 55 53 55 42 55 62',\n",
       "    'endTime': '53 55 53 53 42 55 49',\n",
       "    'department': '14717874 14854807 14925705 14923942 14780072 14856354 14725004 14854817 15638181'},\n",
       "   {'schoolLevel': ['14844587 14847385 15641759 14788518'],\n",
       "    'schoolOriginal': '14792344 14792334 14853024 14854817',\n",
       "    'courses': '',\n",
       "    'education': '14785451 14721174',\n",
       "    'majorOriginal': '15632285 14923942 14856354 14725004',\n",
       "    'endTimeOriginal': '53 55 54 62 14859955 55 49 14785423',\n",
       "    'duration': '51 50',\n",
       "    'educationOriginal': '14785451 14721174',\n",
       "    'major': '14856354 14854817 88 14717874 14854807 14923942 14780072 14726844 88 15632285 14923942 14856354 14725004',\n",
       "    'school': '14792344 14792334 14853024 14854817',\n",
       "    'startTimeOriginal': '53 55 54 50 14859955 55 62 14785423',\n",
       "    'GPA': '',\n",
       "    'ranking': '',\n",
       "    'startTime': '53 55 54 50 42 55 62',\n",
       "    'endTime': '53 55 54 62 42 55 49',\n",
       "    'department': '14716590 14718849 14925705 14923942 14780072 14856354 14725004 14854817 15638181'}],\n",
       "  'profileSocialExps': [{'jobTitle': '15638913 14849695',\n",
       "    'endTimeOriginal': '53 55 54 48 14859955 55 62 14785423',\n",
       "    'duration': '54 53',\n",
       "    'startTimeOriginal': '53 55 54 49 14859955 55 62 14785423',\n",
       "    'organization': '14792344 14792334 14853024 14854817 14788518 14851257 14925473 15638913 14854817 14717848 15638913 14849695 15697555 14849935 14924701',\n",
       "    'location': '',\n",
       "    'startTime': '53 55 54 49 42 55 62',\n",
       "    'endTime': '53 55 54 48 42 55 62',\n",
       "    'department': '',\n",
       "    'jobDescr': '15709080 15709092 14846600 14847406 14852995 14718849 14851257 14925473 15638913 14720387 14782626 14860223 14925196 14847398 14924962 14846093 14851257 14925473 15638913 14723494 14718849 14723726 14856354 14924443 14976901 13 15698352 14858640 14851257 14925473 15638913 15042459 14924703 14721159 15638913 14849695 15042458 15698596 15707534'}],\n",
       "  'profileLanguage': {'languagesOriginal': [{'language': '15699126 15706282',\n",
       "     'proficiency': ['14791302 14717570 14719884 14778501 15699126 14782848 14785175 14782878',\n",
       "      '14782626 14860223 15699126 15706282 14925219 14791302 15697082 14847388']}],\n",
       "   'languages': [{'language': '15699126 15706282',\n",
       "     'proficiency': ['14791302 14717570 14719884 14778501 15699126 14782848 14785175 14782878',\n",
       "      '14782626 14860223 15699126 15706282 14925219 14791302 15697082 14847388']}],\n",
       "   'englishLevel': []},\n",
       "  'profileProjectExps': [{'companyName': '',\n",
       "    'jobTitle': '',\n",
       "    'endTimeOriginal': '15696052 14924941',\n",
       "    'duration': '52 62',\n",
       "    'startTimeOriginal': '53 55 53 54 14859955 55 51 14785423',\n",
       "    'projectDesc': '',\n",
       "    'location': '',\n",
       "    'startTime': '53 55 53 54 42 55 51',\n",
       "    'endTime': '53 55 53 51 42 55 48',\n",
       "    'projectName': '14850237 14925193 14783159 14781097 14724797 15634611 14720387 14853021 14794135 14859141 14784899 14783159 14781097 15637633 14782359 14726332 14728344 14722963 14724785 14925705 14854553 14715319'},\n",
       "   {'companyName': '',\n",
       "    'jobTitle': '',\n",
       "    'endTimeOriginal': '53 55 53 53 14859955 55 54 14785423',\n",
       "    'duration': '54',\n",
       "    'startTimeOriginal': '53 55 53 54 14859955 54 53 14785423',\n",
       "    'projectDesc': '',\n",
       "    'location': '',\n",
       "    'startTime': '53 55 53 54 42 54 53',\n",
       "    'endTime': '53 55 53 53 42 55 54',\n",
       "    'projectName': '14850237 14925193 73 98 115 115 126 14720387 14846644 14782641 15632285 15706536 14726332 14728344 14854553 14715319'},\n",
       "   {'companyName': '',\n",
       "    'jobTitle': '',\n",
       "    'endTimeOriginal': '53 55 53 54 14859955 55 54 14785423',\n",
       "    'duration': '52',\n",
       "    'startTimeOriginal': '53 55 53 55 14859955 54 55 14785423',\n",
       "    'projectDesc': '14717878 14925193 14716590 15697555 14727830 15706553 14852992 14854553 14782906 15710596 14925757 14723463 14846610 15252363 14851261 14924977 15637945 14924962 14782100 15705762 14925702 15252363 14854590 14786452 14846096 14847927 14780081 14779272 14859667 14717871 14720387 14783420 14844092 15252363 15697803 14716590 15697555 14727830 15706553 14852992 14720387 68 87 82 14784945 14784899 14846095 14925706 14858170 14720191 14849931 15252363 14924711 14728344 14720387 14780081 14779272 15710888 14924977 14787719 14791308 14782910 14791826 14858639 15637945 14852744 14783119 15252363 14925757 14925185 15704228 14844340 15710366 14925703 15637945 15639967 15252363 14780567 14844093 14925185 14850237 14925193 14851257 14721689 14728328 14727830 14728347 14720387 14924472 14717871 65 68 64 14924443 14925757 14716606 14858630 14720387 14787719 14791308 14782910 14791826 14976901 13 14858113 14925195 15710364 14847921 14782848 14924977 14925738 14720387 14844090 14783159 14719884 14924443 14786472 14717878 14783626 14924443 14722950 14728323 14782359 14720387 14846114 14854807 15252363 14858138 15706258 14854334 14844593 15710364 15705739 14844090 14783159 14856843 14844578 15252363 14858113 14844090 14783159 14856843 14844578 14924443 14925757 65 68 64 14720387 15699333 14714302 14716606 14858630 15252363 14859953 14924472 14717871 64 73 73 14846396 14780567 14846097 14728340 14784899 14923942 14780072 15252363 15632285 15710336 14728379 14849935 15697796 15630472 65 68 64 14720387 14728340 14784899 14923942 14780072 14849419 15706282 14925454 14923942 14780072 14854334 14785453 14719138 15710888 14924977 15710364 15705739 14787719 14791308 15252363 14847907 14782890 14844593 14786472 14849953 14925757 14780081 14779272 15710888 14924977 14976901 13 14924472 14717871 79 83 74 75 14846093 77 102 113 102 116 100 117 110 119 115 14784899 14859453 14925185 14925703 14925741 15640242 15637157 15252363 14924962 14924188 14717871 14782384 14925709 14924711 14858626 14787719 14791308 14782848 14924977 15252363 14785418 14847398 14851759 14724264 15710359 15705739 14787719 14791308 14924964 14722950 14859953 14851225 14924711 14787719 14791308 14728340 14784923 15252363 14849931 14782641 15706551 14858898 14858900 14847626 14728340 14784923 15696052 74 126 116 86 75',\n",
       "    'location': '',\n",
       "    'startTime': '53 55 53 55 42 54 55',\n",
       "    'endTime': '53 55 53 54 42 55 54',\n",
       "    'projectName': '14850237 14925193 64 73 73 14720387 14859141 14784899 14716590 15697555 14727830 14780081 14779272 15710888 14924977 14720387 14787719 14791308 14726332 14728344'}],\n",
       "  'profileSkills': {'professionalSkills': [{'skill': '14728081 14725004 14850237 14785451 14847384'},\n",
       "    {'skill': '77 102 113 102'},\n",
       "    {'skill': '68'},\n",
       "    {'skill': '87 126 115 111 104 105 15706282 15708039'},\n",
       "    {'skill': '14849929 14724264 14859143 14846102'},\n",
       "    {'skill': '110 102 113 102 14924436 14726332'},\n",
       "    {'skill': '74 126 84 118 107'},\n",
       "    {'skill': '85 98 99 110 116'},\n",
       "    {'skill': '15710364 14725004 15634611 15632285 14923942 14846093 14844593 14720191 14844596 14728081 14725004'}],\n",
       "   'softSkillsOriginal': []},\n",
       "  'profileAwards': {'scholarshipOriginal': ['14788518 14925710 14723726 14852753 14854817 15630486'],\n",
       "   'contestsOriginal': [],\n",
       "   'contests': [],\n",
       "   'certificates': [],\n",
       "   'awards': ['14788518 14721977 14924701 14856354 14924443 14721192 14784902 14847873 14854807 14852753'],\n",
       "   'scholarship': [{'level': '14786217 15632285',\n",
       "     'name': '14788518 14925710 14723726 14852753 14854817 15630486'}],\n",
       "   'thesis': [],\n",
       "   'patents': []},\n",
       "  'profileWorkExps': [],\n",
       "  'profileDesire': {'expectFunction': [],\n",
       "   'expectIndustry': [],\n",
       "   'expectIndustryOriginal': [],\n",
       "   'expectPlace': [],\n",
       "   'currentStatusOriginal': '',\n",
       "   'expectSalary': ''}},\n",
       " 'positionID': '016',\n",
       " 'resumeRecordId': '00001'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8728ab0f-fb48-4e9c-adcf-cde04b04b911",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['positionName', 'resumeData', 'positionID', 'resumeRecordId'])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train[0].keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "87ec807c-a36d-4157-bf44-8f4c70df1a01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['profileEduExps', 'profileSocialExps', 'profileLanguage', 'profileProjectExps', 'profileSkills', 'profileAwards', 'profileWorkExps', 'profileDesire'])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train[0]['resumeData'].keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "22474888-be42-44da-85a0-fdd7d1dc543e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'expectFunction': [],\n",
       " 'expectIndustry': [],\n",
       " 'expectIndustryOriginal': [],\n",
       " 'expectPlace': [],\n",
       " 'currentStatusOriginal': '',\n",
       " 'expectSalary': ''}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train[0]['resumeData']['profileDesire']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "119f9388-2b22-450f-9172-8218529f8e34",
   "metadata": {},
   "source": [
    "## 特征工程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "983c4a84-4f53-49be-9263-e7b35f8d34e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 20000/20000 [10:55<00:00, 30.50it/s]\n"
     ]
    }
   ],
   "source": [
    "# 正则表达式模式，匹配单词，其中单词由空格、标点符号或字符串的开始和结束进行分割\n",
    "pattern = re.compile(r'\\b\\w+\\b')\n",
    "\n",
    "train_feat = []\n",
    "for train_sample in tqdm(train):\n",
    "    cv_sample_word = {}\n",
    "    for key in ['profileEduExps', 'profileSocialExps', 'profileLanguage', 'profileProjectExps', 'profileSkills', 'profileAwards', 'profileWorkExps', 'profileDesire']:\n",
    "        cv_sample_word[key] = pattern.findall(str(train_sample['resumeData'][key]))\n",
    "                           \n",
    "    for job_sample in job_list:\n",
    "        positionName_word = re.findall(pattern, job_sample['positionName'])\n",
    "        positionDescription_word = pattern.findall(job_sample['positionDescription'])\n",
    "        positionRequirements_word = pattern.findall(job_sample['positionRequirements'])\n",
    "\n",
    "        feat = [\n",
    "            len(train_sample['resumeData']['profileEduExps']),\n",
    "        ]\n",
    "\n",
    "        for key in ['profileEduExps', 'profileSocialExps', 'profileLanguage', 'profileProjectExps', 'profileSkills', 'profileAwards', 'profileWorkExps', 'profileDesire']:\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionName_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionDescription_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionRequirements_word)))\n",
    "\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionName_word)) / len(set(positionName_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionDescription_word)) / len(set(positionDescription_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionRequirements_word)) / len(set(positionRequirements_word)))\n",
    "\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionName_word)) / (len(set(cv_sample_word[key])) + 1))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionDescription_word)) / (len(set(cv_sample_word[key])) + 1))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionRequirements_word)) / (len(set(cv_sample_word[key])) + 1))\n",
    "\n",
    "\n",
    "        if train_sample['positionID'] == job_sample['positionID']:\n",
    "            feat.append(1)\n",
    "        else:\n",
    "            feat.append(0)\n",
    "\n",
    "\n",
    "        train_feat.append(feat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1a11551f-850e-4b8a-bb91-f443caf23a9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "train_feat = np.array(train_feat).astype(float)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b65246e6-5dbd-4a60-b12e-b786654812d0",
   "metadata": {},
   "source": [
    "## 模型训练与验证"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4526131c-9bef-48a1-a219-640638029af6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {\n",
       "  /* Definition of color scheme common for light and dark mode */\n",
       "  --sklearn-color-text: black;\n",
       "  --sklearn-color-line: gray;\n",
       "  /* Definition of color scheme for unfitted estimators */\n",
       "  --sklearn-color-unfitted-level-0: #fff5e6;\n",
       "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",
       "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",
       "  --sklearn-color-unfitted-level-3: chocolate;\n",
       "  /* Definition of color scheme for fitted estimators */\n",
       "  --sklearn-color-fitted-level-0: #f0f8ff;\n",
       "  --sklearn-color-fitted-level-1: #d4ebff;\n",
       "  --sklearn-color-fitted-level-2: #b3dbfd;\n",
       "  --sklearn-color-fitted-level-3: cornflowerblue;\n",
       "\n",
       "  /* Specific color for light theme */\n",
       "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
       "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-icon: #696969;\n",
       "\n",
       "  @media (prefers-color-scheme: dark) {\n",
       "    /* Redefinition of color scheme for dark theme */\n",
       "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
       "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-icon: #878787;\n",
       "  }\n",
       "}\n",
       "\n",
       "#sk-container-id-1 {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 pre {\n",
       "  padding: 0;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-hidden--visually {\n",
       "  border: 0;\n",
       "  clip: rect(1px 1px 1px 1px);\n",
       "  clip: rect(1px, 1px, 1px, 1px);\n",
       "  height: 1px;\n",
       "  margin: -1px;\n",
       "  overflow: hidden;\n",
       "  padding: 0;\n",
       "  position: absolute;\n",
       "  width: 1px;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-dashed-wrapped {\n",
       "  border: 1px dashed var(--sklearn-color-line);\n",
       "  margin: 0 0.4em 0.5em 0.4em;\n",
       "  box-sizing: border-box;\n",
       "  padding-bottom: 0.4em;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-container {\n",
       "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
       "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
       "     so we also need the `!important` here to be able to override the\n",
       "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",
       "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
       "  display: inline-block !important;\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-text-repr-fallback {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       "div.sk-parallel-item,\n",
       "div.sk-serial,\n",
       "div.sk-item {\n",
       "  /* draw centered vertical line to link estimators */\n",
       "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
       "  background-size: 2px 100%;\n",
       "  background-repeat: no-repeat;\n",
       "  background-position: center center;\n",
       "}\n",
       "\n",
       "/* Parallel-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item::after {\n",
       "  content: \"\";\n",
       "  width: 100%;\n",
       "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
       "  flex-grow: 1;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel {\n",
       "  display: flex;\n",
       "  align-items: stretch;\n",
       "  justify-content: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
       "  align-self: flex-end;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
       "  align-self: flex-start;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
       "  width: 0;\n",
       "}\n",
       "\n",
       "/* Serial-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-serial {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "  align-items: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  padding-right: 1em;\n",
       "  padding-left: 1em;\n",
       "}\n",
       "\n",
       "\n",
       "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
       "clickable and can be expanded/collapsed.\n",
       "- Pipeline and ColumnTransformer use this feature and define the default style\n",
       "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
       "*/\n",
       "\n",
       "/* Pipeline and ColumnTransformer style (default) */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable {\n",
       "  /* Default theme specific background. It is overwritten whether we have a\n",
       "  specific estimator or a Pipeline/ColumnTransformer */\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "/* Toggleable label */\n",
       "#sk-container-id-1 label.sk-toggleable__label {\n",
       "  cursor: pointer;\n",
       "  display: block;\n",
       "  width: 100%;\n",
       "  margin-bottom: 0;\n",
       "  padding: 0.5em;\n",
       "  box-sizing: border-box;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
       "  /* Arrow on the left of the label */\n",
       "  content: \"▸\";\n",
       "  float: left;\n",
       "  margin-right: 0.25em;\n",
       "  color: var(--sklearn-color-icon);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "/* Toggleable content - dropdown */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content {\n",
       "  max-height: 0;\n",
       "  max-width: 0;\n",
       "  overflow: hidden;\n",
       "  text-align: left;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content pre {\n",
       "  margin: 0.2em;\n",
       "  border-radius: 0.25em;\n",
       "  color: var(--sklearn-color-text);\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
       "  /* Expand drop-down */\n",
       "  max-height: 200px;\n",
       "  max-width: 100%;\n",
       "  overflow: auto;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       "/* Pipeline/ColumnTransformer-specific style */\n",
       "\n",
       "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator-specific style */\n",
       "\n",
       "/* Colorize estimator box */\n",
       "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  /* The background is the default theme color */\n",
       "  color: var(--sklearn-color-text-on-default-background);\n",
       "}\n",
       "\n",
       "/* On hover, darken the color of the background */\n",
       "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "/* Label box, darken color on hover, fitted */\n",
       "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator label */\n",
       "\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  font-family: monospace;\n",
       "  font-weight: bold;\n",
       "  display: inline-block;\n",
       "  line-height: 1.2em;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label-container {\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "/* Estimator-specific */\n",
       "#sk-container-id-1 div.sk-estimator {\n",
       "  font-family: monospace;\n",
       "  border: 1px dotted var(--sklearn-color-border-box);\n",
       "  border-radius: 0.25em;\n",
       "  box-sizing: border-box;\n",
       "  margin-bottom: 0.5em;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "/* on hover */\n",
       "#sk-container-id-1 div.sk-estimator:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
       "\n",
       "/* Common style for \"i\" and \"?\" */\n",
       "\n",
       ".sk-estimator-doc-link,\n",
       "a:link.sk-estimator-doc-link,\n",
       "a:visited.sk-estimator-doc-link {\n",
       "  float: right;\n",
       "  font-size: smaller;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1em;\n",
       "  height: 1em;\n",
       "  width: 1em;\n",
       "  text-decoration: none !important;\n",
       "  margin-left: 1ex;\n",
       "  /* unfitted */\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted,\n",
       "a:link.sk-estimator-doc-link.fitted,\n",
       "a:visited.sk-estimator-doc-link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "/* Span, style for the box shown on hovering the info icon */\n",
       ".sk-estimator-doc-link span {\n",
       "  display: none;\n",
       "  z-index: 9999;\n",
       "  position: relative;\n",
       "  font-weight: normal;\n",
       "  right: .2ex;\n",
       "  padding: .5ex;\n",
       "  margin: .5ex;\n",
       "  width: min-content;\n",
       "  min-width: 20ex;\n",
       "  max-width: 50ex;\n",
       "  color: var(--sklearn-color-text);\n",
       "  box-shadow: 2pt 2pt 4pt #999;\n",
       "  /* unfitted */\n",
       "  background: var(--sklearn-color-unfitted-level-0);\n",
       "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted span {\n",
       "  /* fitted */\n",
       "  background: var(--sklearn-color-fitted-level-0);\n",
       "  border: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link:hover span {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link {\n",
       "  float: right;\n",
       "  font-size: 1rem;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1rem;\n",
       "  height: 1rem;\n",
       "  width: 1rem;\n",
       "  text-decoration: none;\n",
       "  /* unfitted */\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "#sk-container-id-1 a.estimator_doc_link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SGDClassifier(loss=&#x27;log_loss&#x27;)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;&nbsp;SGDClassifier<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.linear_model.SGDClassifier.html\">?<span>Documentation for SGDClassifier</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>SGDClassifier(loss=&#x27;log_loss&#x27;)</pre></div> </div></div></div></div>"
      ],
      "text/plain": [
       "SGDClassifier(loss='log_loss')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import SGDClassifier\n",
    "\n",
    "model = SGDClassifier(loss='log_loss')\n",
    "model.fit(train_feat[:-20000, :-1], train_feat[:-20000, -1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c142fe95-2e79-4623-a475-a8392b3ac6b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9804"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.score(train_feat[-20000:, :-1], train_feat[-20000:, -1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a82d3c88-9c1f-4fbf-a30c-1c710406f438",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[LightGBM] [Info] Number of positive: 19607, number of negative: 980393\n",
      "[LightGBM] [Info] Auto-choosing row-wise multi-threading, the overhead of testing was 0.084207 seconds.\n",
      "You can set `force_row_wise=true` to remove the overhead.\n",
      "And if memory is not enough, you can set `force_col_wise=true`.\n",
      "[LightGBM] [Info] Total Bins 11475\n",
      "[LightGBM] [Info] Number of data points in the train set: 1000000, number of used features: 73\n",
      "[LightGBM] [Info] [binary:BoostFromScore]: pavg=0.019607 -> initscore=-3.912067\n",
      "[LightGBM] [Info] Start training from score -3.912067\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-3 {\n",
       "  /* Definition of color scheme common for light and dark mode */\n",
       "  --sklearn-color-text: black;\n",
       "  --sklearn-color-line: gray;\n",
       "  /* Definition of color scheme for unfitted estimators */\n",
       "  --sklearn-color-unfitted-level-0: #fff5e6;\n",
       "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",
       "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",
       "  --sklearn-color-unfitted-level-3: chocolate;\n",
       "  /* Definition of color scheme for fitted estimators */\n",
       "  --sklearn-color-fitted-level-0: #f0f8ff;\n",
       "  --sklearn-color-fitted-level-1: #d4ebff;\n",
       "  --sklearn-color-fitted-level-2: #b3dbfd;\n",
       "  --sklearn-color-fitted-level-3: cornflowerblue;\n",
       "\n",
       "  /* Specific color for light theme */\n",
       "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
       "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-icon: #696969;\n",
       "\n",
       "  @media (prefers-color-scheme: dark) {\n",
       "    /* Redefinition of color scheme for dark theme */\n",
       "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
       "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-icon: #878787;\n",
       "  }\n",
       "}\n",
       "\n",
       "#sk-container-id-3 {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 pre {\n",
       "  padding: 0;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 input.sk-hidden--visually {\n",
       "  border: 0;\n",
       "  clip: rect(1px 1px 1px 1px);\n",
       "  clip: rect(1px, 1px, 1px, 1px);\n",
       "  height: 1px;\n",
       "  margin: -1px;\n",
       "  overflow: hidden;\n",
       "  padding: 0;\n",
       "  position: absolute;\n",
       "  width: 1px;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-dashed-wrapped {\n",
       "  border: 1px dashed var(--sklearn-color-line);\n",
       "  margin: 0 0.4em 0.5em 0.4em;\n",
       "  box-sizing: border-box;\n",
       "  padding-bottom: 0.4em;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-container {\n",
       "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
       "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
       "     so we also need the `!important` here to be able to override the\n",
       "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",
       "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
       "  display: inline-block !important;\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-text-repr-fallback {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       "div.sk-parallel-item,\n",
       "div.sk-serial,\n",
       "div.sk-item {\n",
       "  /* draw centered vertical line to link estimators */\n",
       "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
       "  background-size: 2px 100%;\n",
       "  background-repeat: no-repeat;\n",
       "  background-position: center center;\n",
       "}\n",
       "\n",
       "/* Parallel-specific style estimator block */\n",
       "\n",
       "#sk-container-id-3 div.sk-parallel-item::after {\n",
       "  content: \"\";\n",
       "  width: 100%;\n",
       "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
       "  flex-grow: 1;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-parallel {\n",
       "  display: flex;\n",
       "  align-items: stretch;\n",
       "  justify-content: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-parallel-item {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-parallel-item:first-child::after {\n",
       "  align-self: flex-end;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-parallel-item:last-child::after {\n",
       "  align-self: flex-start;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-parallel-item:only-child::after {\n",
       "  width: 0;\n",
       "}\n",
       "\n",
       "/* Serial-specific style estimator block */\n",
       "\n",
       "#sk-container-id-3 div.sk-serial {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "  align-items: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  padding-right: 1em;\n",
       "  padding-left: 1em;\n",
       "}\n",
       "\n",
       "\n",
       "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
       "clickable and can be expanded/collapsed.\n",
       "- Pipeline and ColumnTransformer use this feature and define the default style\n",
       "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
       "*/\n",
       "\n",
       "/* Pipeline and ColumnTransformer style (default) */\n",
       "\n",
       "#sk-container-id-3 div.sk-toggleable {\n",
       "  /* Default theme specific background. It is overwritten whether we have a\n",
       "  specific estimator or a Pipeline/ColumnTransformer */\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "/* Toggleable label */\n",
       "#sk-container-id-3 label.sk-toggleable__label {\n",
       "  cursor: pointer;\n",
       "  display: block;\n",
       "  width: 100%;\n",
       "  margin-bottom: 0;\n",
       "  padding: 0.5em;\n",
       "  box-sizing: border-box;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 label.sk-toggleable__label-arrow:before {\n",
       "  /* Arrow on the left of the label */\n",
       "  content: \"▸\";\n",
       "  float: left;\n",
       "  margin-right: 0.25em;\n",
       "  color: var(--sklearn-color-icon);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "/* Toggleable content - dropdown */\n",
       "\n",
       "#sk-container-id-3 div.sk-toggleable__content {\n",
       "  max-height: 0;\n",
       "  max-width: 0;\n",
       "  overflow: hidden;\n",
       "  text-align: left;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-toggleable__content.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-toggleable__content pre {\n",
       "  margin: 0.2em;\n",
       "  border-radius: 0.25em;\n",
       "  color: var(--sklearn-color-text);\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-toggleable__content.fitted pre {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
       "  /* Expand drop-down */\n",
       "  max-height: 200px;\n",
       "  max-width: 100%;\n",
       "  overflow: auto;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       "/* Pipeline/ColumnTransformer-specific style */\n",
       "\n",
       "#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator-specific style */\n",
       "\n",
       "/* Colorize estimator box */\n",
       "#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-label label.sk-toggleable__label,\n",
       "#sk-container-id-3 div.sk-label label {\n",
       "  /* The background is the default theme color */\n",
       "  color: var(--sklearn-color-text-on-default-background);\n",
       "}\n",
       "\n",
       "/* On hover, darken the color of the background */\n",
       "#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "/* Label box, darken color on hover, fitted */\n",
       "#sk-container-id-3 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator label */\n",
       "\n",
       "#sk-container-id-3 div.sk-label label {\n",
       "  font-family: monospace;\n",
       "  font-weight: bold;\n",
       "  display: inline-block;\n",
       "  line-height: 1.2em;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-label-container {\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "/* Estimator-specific */\n",
       "#sk-container-id-3 div.sk-estimator {\n",
       "  font-family: monospace;\n",
       "  border: 1px dotted var(--sklearn-color-border-box);\n",
       "  border-radius: 0.25em;\n",
       "  box-sizing: border-box;\n",
       "  margin-bottom: 0.5em;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-estimator.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "/* on hover */\n",
       "#sk-container-id-3 div.sk-estimator:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-3 div.sk-estimator.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
       "\n",
       "/* Common style for \"i\" and \"?\" */\n",
       "\n",
       ".sk-estimator-doc-link,\n",
       "a:link.sk-estimator-doc-link,\n",
       "a:visited.sk-estimator-doc-link {\n",
       "  float: right;\n",
       "  font-size: smaller;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1em;\n",
       "  height: 1em;\n",
       "  width: 1em;\n",
       "  text-decoration: none !important;\n",
       "  margin-left: 1ex;\n",
       "  /* unfitted */\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted,\n",
       "a:link.sk-estimator-doc-link.fitted,\n",
       "a:visited.sk-estimator-doc-link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "/* Span, style for the box shown on hovering the info icon */\n",
       ".sk-estimator-doc-link span {\n",
       "  display: none;\n",
       "  z-index: 9999;\n",
       "  position: relative;\n",
       "  font-weight: normal;\n",
       "  right: .2ex;\n",
       "  padding: .5ex;\n",
       "  margin: .5ex;\n",
       "  width: min-content;\n",
       "  min-width: 20ex;\n",
       "  max-width: 50ex;\n",
       "  color: var(--sklearn-color-text);\n",
       "  box-shadow: 2pt 2pt 4pt #999;\n",
       "  /* unfitted */\n",
       "  background: var(--sklearn-color-unfitted-level-0);\n",
       "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted span {\n",
       "  /* fitted */\n",
       "  background: var(--sklearn-color-fitted-level-0);\n",
       "  border: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link:hover span {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
       "\n",
       "#sk-container-id-3 a.estimator_doc_link {\n",
       "  float: right;\n",
       "  font-size: 1rem;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1rem;\n",
       "  height: 1rem;\n",
       "  width: 1rem;\n",
       "  text-decoration: none;\n",
       "  /* unfitted */\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 a.estimator_doc_link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "#sk-container-id-3 a.estimator_doc_link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "#sk-container-id-3 a.estimator_doc_link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "</style><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>LGBMClassifier()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;LGBMClassifier<span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>LGBMClassifier()</pre></div> </div></div></div></div>"
      ],
      "text/plain": [
       "LGBMClassifier()"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from lightgbm import LGBMClassifier\n",
    "\n",
    "model = LGBMClassifier()\n",
    "model.fit(train_feat[:-20000, :-1], train_feat[:-20000, -1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "48c724e8-9704-4501-b719-36d5c4d9fd66",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.98045"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.score(train_feat[-20000:, :-1], train_feat[-20000:, -1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "618a5399-065b-4e4a-8025-04dc3254dc08",
   "metadata": {},
   "source": [
    "# 测试集预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "9f96b3e9-2fdb-4579-8bca-7faac98c77a8",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 6500/6500 [04:12<00:00, 25.71it/s]\n"
     ]
    }
   ],
   "source": [
    "test_submit = []\n",
    "for train_sample in tqdm(test):\n",
    "    cv_sample_word = {}\n",
    "    for key in ['profileEduExps', 'profileSocialExps', 'profileLanguage', 'profileProjectExps', 'profileSkills', 'profileAwards', 'profileWorkExps', 'profileDesire']:\n",
    "        cv_sample_word[key] = pattern.findall(str(train_sample['resumeData'][key]))\n",
    "\n",
    "    test_feat = []\n",
    "    for job_sample in job_list:\n",
    "        positionName_word = re.findall(pattern, job_sample['positionName'])\n",
    "        positionDescription_word = pattern.findall(job_sample['positionDescription'])\n",
    "        positionRequirements_word = pattern.findall(job_sample['positionRequirements'])\n",
    "\n",
    "        feat = [\n",
    "            train_sample['resumeRecordId'],\n",
    "            job_sample['positionID'],\n",
    "            len(train_sample['resumeData']['profileEduExps']),\n",
    "        ]\n",
    "\n",
    "        for key in ['profileEduExps', 'profileSocialExps', 'profileLanguage', 'profileProjectExps', 'profileSkills', 'profileAwards', 'profileWorkExps', 'profileDesire']:\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionName_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionDescription_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionRequirements_word)))\n",
    "\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionName_word)) / len(set(positionName_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionDescription_word)) / len(set(positionDescription_word)))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionRequirements_word)) / len(set(positionRequirements_word)))\n",
    "\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionName_word)) / (len(set(cv_sample_word[key])) + 1))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionDescription_word)) / (len(set(cv_sample_word[key])) + 1))\n",
    "            feat.append(len(set(cv_sample_word[key]) & set(positionRequirements_word)) / (len(set(cv_sample_word[key])) + 1))\n",
    "        \n",
    "        test_feat.append(feat)\n",
    "\n",
    "    test_feat = np.array(test_feat)\n",
    "    test_submit.append(\n",
    "        [\n",
    "            train_sample['resumeRecordId'],\n",
    "            test_feat[model.predict_proba(test_feat[:, 2:].astype(float))[:, 1].argmax(), 1]\n",
    "        ]\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "46e8c08c-450b-4ce1-9f15-816783ce60b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_submit = pd.DataFrame(test_submit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "9323542d-28f1-4a75-88dc-6183f651d723",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_submit.columns = ['resumeRecordId', 'positionID']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c6aeddd5-e74f-408d-89d9-57216436f405",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_submit.to_csv('submit.csv', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f58bdb5f-6d4c-40c5-a2e3-7e25785165d6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py3.11",
   "language": "python",
   "name": "py3.11"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
